<%@ page contentType="text/html;charset=utf-8" %>
<%@ page import="ut.data.User" %>
<%@ page import="ut.data.Record" %>
<%@ page import="ut.data.Profile" %>
<%@ page import="ut.res.Language" %>
<%
	User user = (User)session.getAttribute("user");
	if(user == null){
		return;
	}
	
	int tid = 0;
	if(request.getParameter("tid") == null){
		return;
	}else{
		try{
			tid = Integer.parseInt(request.getParameter("tid"));
		}catch(NumberFormatException e){
			return;
		}
	}
	
	int[] favorites = User.getFavorites(user.id);
%>

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>UT終極一翻！ | 邀請使用者接案</title>
	<link rel="stylesheet" type="text/css" href="/style.css" media="all" />
	<link rel="stylesheet" type="text/css" href="/css/popup.css" media="all" />
	<script type="text/javascript" src="/js/Utility.js"></script>
	<script type="text/javascript" src="/js/Message.js"></script>
	<script type="text/javascript" src="/js/Ajax.js"></script>
	<script type="text/javascript" src="/js/Button.js"></script>
	<script type="text/javascript" src="/js/Account.js"></script>
	<script type="text/javascript" src="/js/Task.js"></script>
	<script type="text/javascript" src="/script.js"></script>
</head>
<body onload="init();">
	<div class="content popup">
		<div class="title">邀請使用者接案</div>
<%
	if(User.getUser(favorites[0]) == null){
%>
		<div class="task block">
			<div class="block-center">目前沒有任何關注對象</div>
		</div>
<%
	}else{
		Record record = null;
		Profile profile = null;
		for(int i = 0; i < favorites.length; i++){
			record = Record.getRecord(favorites[i]);
			profile = Profile.getProfile(favorites[i]);
			if(record == null || profile == null){
				continue;
			}
			
			String spec = "";
			if(profile != null){
				Language fromLang = null;
				Language toLang = null;
				for(int j = 0; j < profile.specialties.length; j++){
					fromLang = Language.getLanguage(profile.specialties[j][0]);
					toLang = Language.getLanguage(profile.specialties[j][1]);
					spec += "<span class='spec-lang mark-red'>" + fromLang.title + "</span>";
					spec += " <img src='/image/arrow.png' /> ";
					spec += "<span class='spec-lang mark-red'>" + toLang.title + "</span>";
					
					if(j != profile.specialties.length - 1){
						spec += "；";
					}
				}
			}
%>
		<div class="task block">
			<span class="tag top blue">
				<span class="opener-link"
					onclick="opener.document.location='/account/member-info.jsp?uid=<%= favorites[i] %>&view=2'">
					<%= User.getUserName(favorites[i]) %>
				</span>
			</span>
			<div class="task-content">
				翻譯專長：<%= spec %><br/>
				接案綜合評價：
<%
		if(record.scoreNumber == 0){
%>
						<img src="/image/star-0.png" class="image-middle" />
						<img src="/image/star-0.png" class="image-middle" />
						<img src="/image/star-0.png" class="image-middle" />
						<img src="/image/star-0.png" class="image-middle" />
						<img src="/image/star-0.png" class="image-middle" />
<%
		}else{
			double score = record.score / record.scoreNumber;
			for(int j = 1; j <= 5; j++){
				if(score >= 1){
%>
						<img src="/image/star-2.png" class="image-middle" />
<%
				}else if(score <= 0){
%>
						<img src="/image/star-0.png" class="image-middle" />
<%
				}else{
%>
						<img src="/image/star-1.png" class="image-middle" />
<%
				}
				score--;
			}
		}
%>
				<br/>
				<span class="mark-gray comment">
					（<%= record.scoreNumber %> 人評價；付費案件接案數：<%= record.response %>；
					付費案件成功數：<%= record.success %>；免費案件最佳翻譯數：<%= record.freeSuccess %>）
				</span>
			</div>
			<div class="task-bottom">
				<span class="tag bottom blue tool" onclick="Task.inviteTranslator(<%= tid %>, <%= favorites[i] %>, this)">
					邀請接案
				</span>
			</div>
		</div>
<%
		}
	}
%>
<%@ include file="/include/foot.jsp" %>
	</div>
</body>
</html>